/**
 * Created by Ladyson on 2015/8/26.
 */
loginMoudel.controller("loginMain",function($scope,$http){
    //点击登陆
    $scope.login = function(){
        var name = $scope.name;
        var pwd = $scope.pwd;
        if(name === undefined || pwd === undefined){
            return alert(config.onloginMissVal);
        }else{
            var postData = {username:name,password:pwd};
            postHttp($http,config.login_httpUrl,postData,function(data){
                $.cookie(config.loginName,name);
                if(parseInt(data.data.right) === config.adminUser){
                    window.location.href = config.adminUser_index;
                }else{
                    window.location.href = config.defaultUser_index;
                }
            });
        }
    };

    //点击注册
    $scope.regist = function(){
        var name = $scope.reg_name;
        var pwd = $scope.reg_pwd;
        var rpwd = $scope.reg_rpwd;
        var reg = /^[0-9a-zA-Z]{6,16}$/;
        if(name === undefined || pwd === undefined){
            return alert(config.onloginMissVal);
        }else if(!reg.test(pwd)){
            return alert(config.pwdVal_isRight);
        }else if(pwd != rpwd){
            return alert(config.pwdVal_isSame);
        }else{
            var postData = {username:name,password:pwd};
            postHttp($http,config.regist_httpUrl,postData,function(data){
                alert(config.successRegist);
                window.location.reload();
            });
        }
    }
});


$(document).ready(function(){
    //登陆和注册切换
    $(".change_form span").click(function(){
        var this_form = $(this).parent().parent();
        $(this_form).hide();
        $(this_form).siblings(".form").fadeIn();
    })
});
